

const jumpHref = {

    // 协作组相关地址
    group: {
        create: (authUrl) => {
            return '/group/edit';
        },
        detail: (groupId, authUrl) => {
            return `/group/${groupId}/detail`;
        }
    },

    // 资源相关地址
    resource: {
        publish: () => {
            return '/idx/resource/publish?source=my-resource';
        },

        detail: (id) => {
            return `/resource/detail?source=group-detail&sourceid=${id}`;
        }
    },

    // 活动
    activity: {
        detail: (activityId) => {
            return `/ac2/activity/${activityId}/detail`;
        },
        create: () => {
            return '/ac2/activity/0/edit?bizType=xicheng';
        }
    },

    // 管理中心
    idxmc: {
        index: () => {
            return '/idxmc/home';
        }
    },
    home: { // 门户
        home: () => {
            return '/idx/home';
        },
        userHomePage: () => {
            return '/idx/userCenter/userHomePage';
        },
        myMessage: () => {
            return '/idx/userCenter/message';
        },
        accountSecurity: () => {
            return '/idx/userCenter/accountSecurity';
        },
        mooc: () => { // 慕课广场
            return '/idx/mooc/square';
        },
        myMaterial:() => { // 个人素材库
            return '/idx/userCenter/material';
        }
    },
     // 问卷相关地址
    questionnaire: {
        // 管理问卷题目页面
        create: (id, bizType, queryParams) => { // 问卷id 业务类型
            return `/qc/questionnare/${id}/manage?subBizType=catalogue&bizType=${bizType}${queryParams}`
        },
        // 查看问卷题目页面
        detail: (id, bizType) => { // 问卷id 业务类型
            return `/qc/questionnare/${id}/detail?subBizType=catalogue&bizType=${bizType}`
        },
        answer: (id, subBizId, bizType, lessonId, courseId, lessonType, queryParams) => { //  lesson_summary-总结评价 lesson_assess-问卷
            return `/qc/questionnare/${id}/answer?subBizId=${subBizId}&subBizType=catalogue&bizType=${bizType}&lessonId=${lessonId}&courseId=${courseId}&lessonType=${lessonType}${queryParams}`;
        }
    },
     // 测验跳转问卷相关地址
    questionMoocTest: {
        // 管理问卷题目页面
        create: (id, bizType, queryParams = '') => { // 问卷id 业务类型
            return `/qc/questionnare/${id}/manage?subBizType=mooc_assess${queryParams}`
        },
        // 查看问卷题目页面
        detail: (id, queryParams = '') => { // 问卷id 业务类型
            return `/qc/questionnare/${id}/detail?subBizType=mooc_assess${queryParams}`
        },
        answer: (id, subBizId, queryParams = '') => {
            return `/qc/questionnare/${id}/answer?subBizId=${subBizId}&subBizType=mooc_assess${queryParams}`;
        },
        result: (id, subBizId, queryParams = '') => { // 问卷结果
            return `/qc/questionnare/${id}/result?subBizId=${subBizId}&subBizType=mooc_assess${queryParams}`;
        }
    },

    mooc: {
        moocList: (query) => {
            let url = query ? '?' + query : '';
            return '/idx/userCenter/mooc' + url;
        },
        moocDetail: (moocId) => {
            return `/mooc/course/${moocId}/detail`
        },
        moocCatalogueDetail: (moocId) => {
            return `/mooc/catalogue/${moocId}/detail`
        },
        moocAnswerTask: (moocId) => {
            return `/mooc/task/${moocId}/answer`
        },
        moocViewTask: (moocId) => {
            return `/mooc/task/${moocId}/detail`
        },
        moocManage: (moocId, tabStr) => {
            let url = tabStr ? '?tabStr=' + tabStr : '';
            return `/mooc/manage/${moocId}/detail` + url
        }
    },
    strain: { // 培训
        index: () => {
            return '/strain/home';
        },
        moocDetail: (moocId) => {
            return `/mooc/course/${moocId}/straindetail`
        },
        moocCatalogueDetail: (moocId) => {
            return `/mooc/catalogue/${moocId}/straindetail`
        },
        moocAnswerTask: (moocId) => {
            return `/mooc/task/${moocId}/strainanswer`
        },
        moocViewTask: (moocId) => {
            return `/mooc/task/${moocId}/straindetail`
        },
        topicDetail: (topicId) => {
            return `/mooc/topic/${topicId}/detail`
        },
        strainTopicDetail: (topicId) => {
            return `/mooc//topic/${topicId}/straindetail`
        }
    },
    course: { // 研修课程
        detail: (courseId) => {
            return `/idx/course/details?courseId=${courseId}`
        }
    }
}

const getUrl = (keys, obj = jumpHref) => {
    let keySpre = keys.constructor == Array ? keys : keys.split('.');
    if (!obj[keySpre[0]]) {
        return false;
    }
    if (keySpre.length == 1 && obj[keySpre[0]]) {
        if (typeof obj[keySpre[0]] == 'string') {
            return obj[keySpre[0]];
        }
        return obj[keySpre[0]]();
    }
    let state = getUrl(keySpre.splice(1), obj[keySpre[0]]);
    return state;
}

export {
    jumpHref
};

export {
    getUrl
}
